package pbm.com.datamanager;

import android.util.TimeUtils;

import com.data.collect.tool.DateTools;
import com.data.collect.tool.MD5Util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;

/**
 * Created by wanggenlin on 17-6-16.
 */
public class Test {


    public static void main(String[] strings){
    String url = "http://140.206.72.238:10011/scanpay-api/api/unifiedOrder20";
    String key = "OVBD7pAsP4w43h4L90mDXNUBIVlKfVUZ";
    String reqTime = DateTools.dateFormatterOfDateTimeForNow(DateTools.DATE_FORMAT_STYLE_1);
        System.out.println("reqTime = "+reqTime);
    String merNo = "1469009202";
        System.out.println("merNo = "+merNo);
    String orderNo = reqTime;
        System.out.println("orderNo = "+orderNo);
    String channelFlag ="00";
        System.out.println("channelFlag = "+channelFlag);
    String amount = "100";
        System.out.println("amount = "+amount);
    Map<String, Object> map = new HashMap<>();
    map.put("merNo", merNo);
    map.put("orderNo", orderNo);
    map.put("channelFlag", channelFlag);
    map.put("amount", amount);
    map.put("reqTime", reqTime);
    map.put("reqId", reqTime);

    String signIn = getSign(map, key);
        System.out.println("signIn = "+signIn);
    System.out.println(signIn);

}

    public static String getSign(Map<String, Object> map, String key) {

        try {

            ArrayList list = new ArrayList();
            Iterator size = map.entrySet().iterator();

            while(size.hasNext()) {
                Map.Entry arrayToSort = (Map.Entry)size.next();
                if(arrayToSort.getValue() != "") {
                    list.add((String)arrayToSort.getKey() + "=" + arrayToSort.getValue() + "&");
                }
            }

            int var6 = list.size();
            String[] var7 = (String[])list.toArray(new String[var6]);
            Arrays.sort(var7, String.CASE_INSENSITIVE_ORDER);
            StringBuilder sb = new StringBuilder();

            for(int result = 0; result < var6; ++result) {
                sb.append(var7[result]);
            }

            sb.deleteCharAt(sb.length() - 1);

            String var8 = sb.toString();
            var8 = var8 + key;
            var8 = MD5Util.Bit32(var8).toUpperCase();
            return var8;


        } catch (Exception e) {
        }
        return "";
    }


}
